{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "48702ea7-3cb4-4e9a-adec-d5e478f28adc",
   "metadata": {},
   "source": [
    "# Analytics for Keyword Expansion\n",
    "\n",
    "Let's imagine we are sitting in the marketing department of a company selling jewelry. We need to plan a campaign with some corner points:\n",
    "- it should be running on Facebook Ads\n",
    "- it should be approximately a month long\n",
    "- we should spend ballpark 500 USD on it daily\n",
    "- the ad creative is not perfectly set, but should be centered around the term \"embrace your individuality\"\n",
    "\n",
    "Now, we have to find keywords to target the ad with.\n",
    "\n",
    "In order to do that, we have past campaign data at our disposal. In this notebook the aim is to showcase how to drill through the data effectively to help our efforts finding the best keywords."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "2786a201-16bc-42c2-9b00-6e61f39fd67d",
   "metadata": {},
   "outputs": [],
   "source": [
    "%pip install superlinked==37.5.0\n",
    "%pip install matplotlib"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "7ce1d1b7-7058-489e-a1e8-42d98074c5db",
   "metadata": {},
   "outputs": [],
   "source": [
    "from datetime import datetime, timedelta\n",
    "import os\n",
    "import sys\n",
    "import warnings\n",
    "import altair as alt\n",
    "import pandas as pd\n",
    "from superlinked import framework as sl\n",
    "\n",
    "alt.data_transformers.disable_max_rows()\n",
    "alt.renderers.enable(sl.get_altair_renderer())\n",
    "pd.set_option(\"display.max_rows\", 120)\n",
    "pd.set_option(\"display.max_columns\", 50)\n",
    "pd.set_option(\"display.float_format\", lambda x: f\"{x:.3f}\")\n",
    "# silence torch warning from sentence_transformers\n",
    "warnings.filterwarnings(\"ignore\", category=UserWarning, message=\"TypedStorage is deprecated\")\n",
    "\n",
    "END_OF_2022_12_10_TS = int(datetime(2022, 12, 11).timestamp())\n",
    "EXECUTOR_DATA = {sl.CONTEXT_COMMON: {sl.CONTEXT_COMMON_NOW: END_OF_2022_12_10_TS}}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "4cdfc511-45d6-4104-8286-c2774d9855c4",
   "metadata": {},
   "outputs": [],
   "source": [
    "def describe_with_percentiles(\n",
    "    series: pd.Series,\n",
    "    percentiles: list[float] | None = None,\n",
    ") -> pd.Series:\n",
    "    \"\"\"\n",
    "    Wrapper around pd.series.describe() giving the percentiles arg a different default.\n",
    "    \"\"\"\n",
    "    if percentiles is None:\n",
    "        percentiles = [0.05, 0.1, 0.25, 0.5, 0.75, 0.9, 0.95, 0.99, 0.995]\n",
    "    return series.describe(percentiles=percentiles)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "d62eacd6-66f2-4028-8823-1f654a678f1a",
   "metadata": {},
   "outputs": [],
   "source": [
    "DATASET_URL: str = (\n",
    "    \"https://storage.googleapis.com/superlinked-notebook-analytics-keyword-expansion-ads/marketing-dataset-filtered.csv\"\n",
    ")\n",
    "USE_COLUMNS: list[str] = [\n",
    "    \"time\",\n",
    "    \"media_cost_usd\",\n",
    "    \"no_of_days\",\n",
    "    \"search_tags\",\n",
    "    \"keywords\",\n",
    "    \"ext_service_name\",\n",
    "    \"clicks\",\n",
    "]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1d161a5a-f680-4a99-bacf-efe0876d6e66",
   "metadata": {},
   "source": [
    "## Load and clean dataset"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "14df7294-e9cc-4fb1-b578-196b2ca1f607",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>index</th>\n",
       "      <th>campaign_item_id</th>\n",
       "      <th>no_of_days</th>\n",
       "      <th>time</th>\n",
       "      <th>ext_service_id</th>\n",
       "      <th>ext_service_name</th>\n",
       "      <th>creative_id</th>\n",
       "      <th>creative_width</th>\n",
       "      <th>creative_height</th>\n",
       "      <th>search_tags</th>\n",
       "      <th>template_id</th>\n",
       "      <th>landing_page</th>\n",
       "      <th>advertiser_id</th>\n",
       "      <th>advertiser_name</th>\n",
       "      <th>network_id</th>\n",
       "      <th>approved_budget</th>\n",
       "      <th>advertiser_currency</th>\n",
       "      <th>channel_id</th>\n",
       "      <th>channel_name</th>\n",
       "      <th>max_bid_cpm</th>\n",
       "      <th>network_margin</th>\n",
       "      <th>campaign_budget_usd</th>\n",
       "      <th>impressions</th>\n",
       "      <th>clicks</th>\n",
       "      <th>stats_currency</th>\n",
       "      <th>currency_code</th>\n",
       "      <th>exchange_rate</th>\n",
       "      <th>media_cost_usd</th>\n",
       "      <th>position_in_content</th>\n",
       "      <th>unique_reach</th>\n",
       "      <th>total_reach</th>\n",
       "      <th>search_tag_cat</th>\n",
       "      <th>cmi_currency_code</th>\n",
       "      <th>timezone</th>\n",
       "      <th>weekday_cat</th>\n",
       "      <th>keywords</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>2733</td>\n",
       "      <td>9</td>\n",
       "      <td>2022-05-03</td>\n",
       "      <td>128</td>\n",
       "      <td>Facebook Ads</td>\n",
       "      <td>1000</td>\n",
       "      <td>300.000</td>\n",
       "      <td>250.000</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>90.000</td>\n",
       "      <td>https://www.abcjewelry.com/collections/boho-je...</td>\n",
       "      <td>4756</td>\n",
       "      <td>Web</td>\n",
       "      <td>190</td>\n",
       "      <td>400.000</td>\n",
       "      <td>SGD</td>\n",
       "      <td>8</td>\n",
       "      <td>Social</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.000</td>\n",
       "      <td>652.174</td>\n",
       "      <td>2135</td>\n",
       "      <td>32</td>\n",
       "      <td>SGD</td>\n",
       "      <td>SGD</td>\n",
       "      <td>1</td>\n",
       "      <td>109.420</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Others</td>\n",
       "      <td>SGD</td>\n",
       "      <td>Asia/Singapore</td>\n",
       "      <td>week_day</td>\n",
       "      <td>artisan jewelry</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>2766</td>\n",
       "      <td>54</td>\n",
       "      <td>2022-06-01</td>\n",
       "      <td>4</td>\n",
       "      <td>Google Ads</td>\n",
       "      <td>1005</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>#The Ultimate Fashion Statement with X</td>\n",
       "      <td>23.000</td>\n",
       "      <td>https://www.abcjewelry.com/collections/gemston...</td>\n",
       "      <td>5191</td>\n",
       "      <td>Brand</td>\n",
       "      <td>287</td>\n",
       "      <td>1000.000</td>\n",
       "      <td>USD</td>\n",
       "      <td>32</td>\n",
       "      <td>Mobile</td>\n",
       "      <td>1.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>760.000</td>\n",
       "      <td>876</td>\n",
       "      <td>18</td>\n",
       "      <td>USD</td>\n",
       "      <td>USD</td>\n",
       "      <td>1</td>\n",
       "      <td>43.151</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Youtube</td>\n",
       "      <td>USD</td>\n",
       "      <td>America/New_York</td>\n",
       "      <td>week_day</td>\n",
       "      <td>bridal jewelry</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>2766</td>\n",
       "      <td>55</td>\n",
       "      <td>2022-06-02</td>\n",
       "      <td>16</td>\n",
       "      <td>DV360</td>\n",
       "      <td>1005</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>#The Ultimate Fashion Statement with X</td>\n",
       "      <td>23.000</td>\n",
       "      <td>https://www.abcjewelry.com/collections/stateme...</td>\n",
       "      <td>5191</td>\n",
       "      <td>Brand</td>\n",
       "      <td>287</td>\n",
       "      <td>1000.000</td>\n",
       "      <td>USD</td>\n",
       "      <td>1</td>\n",
       "      <td>Display</td>\n",
       "      <td>1.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>760.000</td>\n",
       "      <td>790</td>\n",
       "      <td>12</td>\n",
       "      <td>USD</td>\n",
       "      <td>USD</td>\n",
       "      <td>1</td>\n",
       "      <td>31.436</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Youtube</td>\n",
       "      <td>USD</td>\n",
       "      <td>America/New_York</td>\n",
       "      <td>week_day</td>\n",
       "      <td>unique and trendy jewelry</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>2766</td>\n",
       "      <td>58</td>\n",
       "      <td>2022-06-05</td>\n",
       "      <td>128</td>\n",
       "      <td>Facebook Ads</td>\n",
       "      <td>1005</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>23.000</td>\n",
       "      <td>https://www.abcjewelry.com/collections/gemston...</td>\n",
       "      <td>5191</td>\n",
       "      <td>Brand</td>\n",
       "      <td>287</td>\n",
       "      <td>1000.000</td>\n",
       "      <td>USD</td>\n",
       "      <td>4</td>\n",
       "      <td>Search</td>\n",
       "      <td>1.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>760.000</td>\n",
       "      <td>655</td>\n",
       "      <td>12</td>\n",
       "      <td>USD</td>\n",
       "      <td>USD</td>\n",
       "      <td>1</td>\n",
       "      <td>13.351</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Youtube</td>\n",
       "      <td>USD</td>\n",
       "      <td>America/New_York</td>\n",
       "      <td>week_end</td>\n",
       "      <td>artisan jewelry</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>2766</td>\n",
       "      <td>62</td>\n",
       "      <td>2022-06-09</td>\n",
       "      <td>128</td>\n",
       "      <td>Facebook Ads</td>\n",
       "      <td>1005</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>23.000</td>\n",
       "      <td>https://www.abcjewelry.com/collections/pendant...</td>\n",
       "      <td>5191</td>\n",
       "      <td>Brand</td>\n",
       "      <td>287</td>\n",
       "      <td>1000.000</td>\n",
       "      <td>USD</td>\n",
       "      <td>64</td>\n",
       "      <td>Video</td>\n",
       "      <td>1.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>760.000</td>\n",
       "      <td>622</td>\n",
       "      <td>10</td>\n",
       "      <td>USD</td>\n",
       "      <td>USD</td>\n",
       "      <td>1</td>\n",
       "      <td>13.629</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Youtube</td>\n",
       "      <td>USD</td>\n",
       "      <td>America/New_York</td>\n",
       "      <td>week_day</td>\n",
       "      <td>rhinestone jewelry</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   index  campaign_item_id  no_of_days        time  ext_service_id  \\\n",
       "0      0              2733           9  2022-05-03             128   \n",
       "1      1              2766          54  2022-06-01               4   \n",
       "2      2              2766          55  2022-06-02              16   \n",
       "3      3              2766          58  2022-06-05             128   \n",
       "4      4              2766          62  2022-06-09             128   \n",
       "\n",
       "  ext_service_name  creative_id  creative_width  creative_height  \\\n",
       "0     Facebook Ads         1000         300.000          250.000   \n",
       "1       Google Ads         1005           0.000            0.000   \n",
       "2            DV360         1005           0.000            0.000   \n",
       "3     Facebook Ads         1005           0.000            0.000   \n",
       "4     Facebook Ads         1005           0.000            0.000   \n",
       "\n",
       "                              search_tags  template_id  \\\n",
       "0      #Embrace Your Individuality with X       90.000   \n",
       "1  #The Ultimate Fashion Statement with X       23.000   \n",
       "2  #The Ultimate Fashion Statement with X       23.000   \n",
       "3      #Embrace Your Individuality with X       23.000   \n",
       "4      #Embrace Your Individuality with X       23.000   \n",
       "\n",
       "                                        landing_page  advertiser_id  \\\n",
       "0  https://www.abcjewelry.com/collections/boho-je...           4756   \n",
       "1  https://www.abcjewelry.com/collections/gemston...           5191   \n",
       "2  https://www.abcjewelry.com/collections/stateme...           5191   \n",
       "3  https://www.abcjewelry.com/collections/gemston...           5191   \n",
       "4  https://www.abcjewelry.com/collections/pendant...           5191   \n",
       "\n",
       "  advertiser_name  network_id  approved_budget advertiser_currency  \\\n",
       "0             Web         190          400.000                 SGD   \n",
       "1           Brand         287         1000.000                 USD   \n",
       "2           Brand         287         1000.000                 USD   \n",
       "3           Brand         287         1000.000                 USD   \n",
       "4           Brand         287         1000.000                 USD   \n",
       "\n",
       "   channel_id channel_name  max_bid_cpm  network_margin  campaign_budget_usd  \\\n",
       "0           8       Social          NaN           0.000              652.174   \n",
       "1          32       Mobile        1.000           0.000              760.000   \n",
       "2           1      Display        1.000           0.000              760.000   \n",
       "3           4       Search        1.000           0.000              760.000   \n",
       "4          64        Video        1.000           0.000              760.000   \n",
       "\n",
       "   impressions  clicks stats_currency currency_code  exchange_rate  \\\n",
       "0         2135      32            SGD           SGD              1   \n",
       "1          876      18            USD           USD              1   \n",
       "2          790      12            USD           USD              1   \n",
       "3          655      12            USD           USD              1   \n",
       "4          622      10            USD           USD              1   \n",
       "\n",
       "   media_cost_usd  position_in_content  unique_reach  total_reach  \\\n",
       "0         109.420                  NaN           NaN          NaN   \n",
       "1          43.151                  NaN           NaN          NaN   \n",
       "2          31.436                  NaN           NaN          NaN   \n",
       "3          13.351                  NaN           NaN          NaN   \n",
       "4          13.629                  NaN           NaN          NaN   \n",
       "\n",
       "  search_tag_cat cmi_currency_code          timezone weekday_cat  \\\n",
       "0         Others               SGD    Asia/Singapore    week_day   \n",
       "1        Youtube               USD  America/New_York    week_day   \n",
       "2        Youtube               USD  America/New_York    week_day   \n",
       "3        Youtube               USD  America/New_York    week_end   \n",
       "4        Youtube               USD  America/New_York    week_day   \n",
       "\n",
       "                    keywords  \n",
       "0            artisan jewelry  \n",
       "1             bridal jewelry  \n",
       "2  unique and trendy jewelry  \n",
       "3            artisan jewelry  \n",
       "4         rhinestone jewelry  "
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "NROWS = int(os.getenv(\"NOTEBOOK_TEST_ROW_LIMIT\", str(sys.maxsize)))\n",
    "dataset = pd.read_csv(DATASET_URL, nrows=NROWS).reset_index()\n",
    "dataset.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "f8210e40-fa47-40f5-bf6b-e421a4a0efdc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(23886, 11)"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "filtered_df = dataset.loc[:, USE_COLUMNS].reset_index().copy()\n",
    "# filtering for campaigns with spending and days info\",\n",
    "filtered_dataset = filtered_df[filtered_df[\"no_of_days\"] > 0]\n",
    "filtered_dataset = filtered_dataset[filtered_dataset[\"media_cost_usd\"] > 0]\n",
    "# calculate and clean\",\n",
    "filtered_dataset[\"time\"] = [int(f.timestamp()) for f in pd.to_datetime(filtered_dataset.loc[:, \"time\"])]\n",
    "filtered_dataset[\"daily_cost\"] = filtered_dataset.loc[:, \"media_cost_usd\"] / filtered_dataset.loc[:, \"no_of_days\"]\n",
    "filtered_dataset[\"daily_click\"] = filtered_dataset.loc[:, \"clicks\"] / filtered_dataset.loc[:, \"no_of_days\"]\n",
    "filtered_dataset[\"cost_per_click\"] = filtered_dataset.loc[:, \"media_cost_usd\"] / filtered_dataset.loc[:, \"clicks\"]\n",
    "filtered_dataset.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "b7c7a48e-706d-4389-9266-626b992509df",
   "metadata": {},
   "outputs": [],
   "source": [
    "# uncomment this line to run on a smaller sample of data for a lightning fast run\n",
    "# filtered_dataset = filtered_dataset.sample(2000)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ac8ddfc3-cdc6-48d7-98be-28856c2eb5f7",
   "metadata": {},
   "source": [
    "## Data exploration\n",
    "\n",
    "To find the right space parameters."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "d330236e-6eb4-472b-b5fd-b805bc872d50",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Axes: >"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAjAAAAGdCAYAAAAMm0nCAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAzfElEQVR4nO3dfXhU5YH+8XsGkpAgkxA0CakBc+1ay4uKhRKi1qKERKAWlF2XmirbZWXFREvTpZquYMAXICAiSEW6inVLWrXbUhdYYITa0BJ5iUYNRaAtFldJ6BrDGCjDwDy/P9zMjyHveAJ5cr6f65oL55xnnnnuDJrbc87MeIwxRgAAABbxXugFAAAAdBQFBgAAWIcCAwAArEOBAQAA1qHAAAAA61BgAACAdSgwAADAOhQYAABgnZ4XegGdJRwO66OPPlKfPn3k8Xgu9HIAAEA7GGP06aefKj09XV5vy8dZum2B+eijj5SRkXGhlwEAAM7BBx98oEsvvbTF/d22wPTp00fSZz8An8/n2LyhUEibN29Wbm6uYmJiHJvXBm7M7sbMkntzS+7M7sbMkjtz25A5EAgoIyM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G7MLLk3t+TO7G7MLLkztw2ZjTH69NNPlZ6e3uq4LllgLr74YvXo0UO1tbVR22tra5WWltbsY+Li4hQXFxe1LSkpqbOWKJ/P12Vf/M7mxuxuzCy5N7fkzuxuzCy5M3dXz5yYmNjmmC75QXaxsbEaPny4tmzZEtkWDoe1ZcsWZWdnX8CVAQCArqBLHoGRpKKiIk2dOlUjRozQyJEjtXTpUh07dizyriQAAOBeXbbA/MM//IP+8pe/aM6cOaqpqdGwYcO0ceNGpaamXtB1xcXF6eGHH25yusoN3JjdjZkl9+aW3JndjZkld+buTpk9xrT1PiUAAICupUteAwMAANAaCgwAALAOBQYAAFiHAgMAAKzTbQrM/Pnz9ZWvfEV9+vRRSkqKJk2apH379kWNOXHihAoKCtSvXz9ddNFFmjx5ctSH5b399tv65je/qYyMDMXHx2vQoEF66qmnoub4xS9+obFjx+qSSy6Rz+dTdna2Nm3a1Ob6jDGaM2eO+vfvr/j4eOXk5OjAgQNRYy677DJ5PJ6o24IFC7p9bklav369srKyFB8fr759+2rSpEndNvPrr7/e5HVuvO3atavVuW3PLkn79+/XxIkTdfHFF8vn8+n666/Xr3/9626f+80339TYsWOVlJSkfv36afr06WpoaLA28y9+8Qvl5uZGPu28qqqqyZi21teds69atUqjR4+Wz+eTx+NRfX19t81bV1en++67T1dccYXi4+M1YMAA3X///ZHvJOw0n/uLi7qIvLw8s3r1alNdXW2qqqrM+PHjzYABA0xDQ0NkzD333GMyMjLMli1bzO7du82oUaPMtddeG9n/3HPPmfvvv9+8/vrr5o9//KP5j//4DxMfH2+WL18eGfOd73zHLFy40OzcudPs37/fFBcXm5iYGPPmm2+2ur4FCxaYxMREs3btWvP222+bb3zjGyYzM9P89a9/jYwZOHCgmTdvnjl8+HDkdub6u2vun//856Zv377mmWeeMfv27TN79uwxL730UrfNHAwGo17jw4cPm3/+5382mZmZJhwOtzq37dmNMebyyy8348ePN2+//bbZv3+/uffee01CQoI5fPhwt8394Ycfmr59+5p77rnHvPfee2bnzp3m2muvNZMnT7Y284svvmjmzp1rfvSjHxlJ5q233moypq31defsTz75pJk/f76ZP3++kWQ++eSTbpv33XffNbfddpt59dVXzR/+8AezZcsWc/nll7f699sJ3abAnO3IkSNGkvnNb35jjDGmvr7exMTEmFdeeSUyZu/evUaSqaioaHGee++919x4442tPtfgwYPN3LlzW9wfDodNWlqaWbRoUWRbfX29iYuLMz/96U8j2wYOHGiefPLJtqK1yrbcoVDIfOELXzD//u//3q58zbEt89lOnjxpLrnkEjNv3rxWn7s5tmX/y1/+YiSZ8vLyyJhAIGAkGb/f33rYM9iW+9lnnzUpKSnm9OnTkTHvvPOOkWQOHDjQetj/05Uyn+ngwYPN/lI71/U1x7bsZ/r1r3/dZoE5m815G7388ssmNjbWhEKhds19LrrNKaSzNR66Sk5OliRVVlYqFAopJycnMuZLX/qSBgwYoIqKilbnaZyjOeFwWJ9++mmrYw4ePKiampqo505MTFRWVlaT516wYIH69euna665RosWLdKpU6daD9rMeiV7cr/55pv68MMP5fV6dc0116h///4aN26cqqur2xdY9mU+26uvvqqPP/74nD5l2rbs/fr10xVXXKEXX3xRx44d06lTp/Tss88qJSVFw4cPb19o2Zc7GAwqNjZWXu///09ufHy8JOm3v/1ta1Gj1ip1jcztca7ra45t2T+v7pD36NGj8vl86tmz8z4vt8t+Eu/nEQ6HNXPmTF133XUaOnSoJKmmpkaxsbFNvuAxNTVVNTU1zc6zfft2vfTSS1q/fn2Lz7V48WI1NDTo9ttvb3FM4/xnf4rw2c99//3368tf/rKSk5O1fft2FRcX6/Dhw1qyZEmreRvZmPtPf/qTJKmkpERLlizRZZddpieeeEKjR4/W/v372/wXy8bMZ3vuueeUl5enSy+9tMV5m2Njdo/Ho9dee02TJk1Snz595PV6lZKSoo0bN6pv375tZpbszH3TTTepqKhIixYt0ne+8x0dO3ZMDz74oCTp8OHDrQdW18vcHueyvubYmP3z6A55//d//1ePPPKIpk+f7ui8Z+uWR2AKCgpUXV2tn/3sZ+c8R3V1tSZOnKiHH35Yubm5zY4p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u3dvqfN0p+1/+8hfTr18/c9ttt5mqqiqzb98+86//+q8mJibGVFVVddvcxhizfPlyU1lZafbt22eefvppEx8fb5566ilrM3/88cfmrbfeMuvXrzeSzM9+9jPz1ltvRb0dvq31defshw8fNm+99Vbkrcfl5eXmrbfeMh9//HG3y3v06FGTlZVlrrzySvOHP/whau5Tp061Ovfn0W0KjKRmb6tXr46M+etf/2ruvfde07dvX5OQkGBuvfXWqL9wDz/8cLNzDBw4MDLma1/7WrNjpk6d2ur6wuGwmT17tklNTTVxcXFmzJgxZt++fZH9lZWVJisryyQmJppevXqZQYMGmccff9ycOHGiW+c25rMjLt/73vdMSkqK6dOnj8nJyTHV1dXdOrMxxnzzm99s12didLfsu3btMrm5uSY5Odn06dPHjBo1ymzYsKHb577zzjtNcnKyiY2NNVdddZV58cUXrc68evXqZh/38MMPt3t93Tl7S89/ZobukrfxKFNzt4MHD7Y69+fhMcYYAQAAWKRbvgsJAAB0bxQYAABgHQoMAACwDgUGAABYhwIDAACsQ4EBAADWocAAAADrUGAAAIB1KDAAAMA6FBgAAGAdCgwAALAOBQYAAFjn/wHQMOn/DJ5UPAAAAABJRU5ErkJggg==",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pd.to_datetime(filtered_dataset[\"time\"], unit=\"s\").hist(bins=50)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7acc1b86-316a-43d1-9c8d-6a1224d90865",
   "metadata": {},
   "source": [
    "Recency space should have two period times - one for the frequent 2 months, and 8 months to cover the whole span of time campaigns happened.\n",
    "\n",
    "See other space parameters inline with the corresponding table creation."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "5f469d4f-3c76-4ea0-b7d9-384c42f7e03f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "count   23886.000\n",
       "mean       27.798\n",
       "std        25.445\n",
       "min         1.000\n",
       "5%          2.000\n",
       "10%         4.000\n",
       "25%         9.000\n",
       "50%        20.000\n",
       "75%        37.000\n",
       "90%        65.000\n",
       "95%        85.000\n",
       "99%       111.150\n",
       "99.5%     115.000\n",
       "max       118.000\n",
       "Name: no_of_days, dtype: float64"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# encode between [0-100] using NumberSpace with Similar mode\n",
    "# as we might prefer varying campaign lengths based on our preferences\n",
    "describe_with_percentiles(filtered_dataset[\"no_of_days\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "68985269-947f-4d44-8758-a18db9ad21ff",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "count   23886.000\n",
       "mean       52.834\n",
       "std       365.499\n",
       "min         2.000\n",
       "5%          3.000\n",
       "10%         3.000\n",
       "25%         5.000\n",
       "50%         8.000\n",
       "75%        13.000\n",
       "90%        82.000\n",
       "95%       157.000\n",
       "99%       742.150\n",
       "99.5%    1431.675\n",
       "max     20644.000\n",
       "Name: clicks, dtype: float64"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# very skewed, depends on no_of_days, not embedding it!\n",
    "describe_with_percentiles(filtered_dataset[\"clicks\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "3ace1b57-fff8-4eb4-933e-c1768b455cef",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "count   23886.000\n",
       "mean        2.067\n",
       "std        23.388\n",
       "min         0.000\n",
       "5%          0.002\n",
       "10%         0.005\n",
       "25%         0.018\n",
       "50%         0.085\n",
       "75%         0.642\n",
       "90%         3.341\n",
       "95%         6.861\n",
       "99%        29.464\n",
       "99.5%      46.276\n",
       "max      2295.029\n",
       "Name: daily_cost, dtype: float64"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# encode between [0, 50] outliers would skew the distribution.\n",
    "# Use NumberSpace with Similar mode as we might have different budgets\n",
    "describe_with_percentiles(filtered_dataset[\"daily_cost\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "f2beb117-763e-42f9-9000-459487ca91d4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "count   23886.000\n",
       "mean        7.773\n",
       "std        93.427\n",
       "min         0.017\n",
       "5%          0.065\n",
       "10%         0.091\n",
       "25%         0.174\n",
       "50%         0.400\n",
       "75%         1.556\n",
       "90%         9.564\n",
       "95%        22.650\n",
       "99%       107.858\n",
       "99.5%     205.331\n",
       "max      8090.000\n",
       "Name: daily_click, dtype: float64"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# encode between [0, 100] outliers would skew the distribution.\n",
    "# Use NumberSpace with Maximum Mode as we prefer better daily_click bringing campaigns all else being equal\n",
    "describe_with_percentiles(filtered_dataset[\"daily_click\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "5ec9b8c1-d717-4674-8c33-c2a98ee9124b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "count   23886.000\n",
       "mean        0.402\n",
       "std         0.666\n",
       "min         0.000\n",
       "5%          0.011\n",
       "10%         0.023\n",
       "25%         0.070\n",
       "50%         0.204\n",
       "75%         0.450\n",
       "90%         0.947\n",
       "95%         1.439\n",
       "99%         3.253\n",
       "99.5%       4.262\n",
       "max        15.728\n",
       "Name: cost_per_click, dtype: float64"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# encode between [0, 2] outliers would skew the distribution.\n",
    "# Use NumberSpace with Minimum Mode as we prefer campaigns that achieve a click spending less dollars.\n",
    "# Measured in thousand USD.\n",
    "describe_with_percentiles(filtered_dataset[\"cost_per_click\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "71e1515a-e5b7-41ba-8656-4788dcdbcaf4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "ext_service_name\n",
       "Facebook Ads    7972\n",
       "Google Ads      7957\n",
       "DV360           7957\n",
       "Name: count, dtype: int64"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# low cardinality categorical variable, let's use CategoricalSimilaritySpace!\n",
    "filtered_dataset[\"ext_service_name\"].value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "0352e1bb-8447-4d59-9d5c-72fc3efa8c49",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>index</th>\n",
       "      <th>time</th>\n",
       "      <th>media_cost_usd</th>\n",
       "      <th>no_of_days</th>\n",
       "      <th>search_tags</th>\n",
       "      <th>keywords</th>\n",
       "      <th>ext_service_name</th>\n",
       "      <th>clicks</th>\n",
       "      <th>daily_cost</th>\n",
       "      <th>daily_click</th>\n",
       "      <th>cost_per_click</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>1651536000</td>\n",
       "      <td>109.420</td>\n",
       "      <td>9</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>artisan jewelry</td>\n",
       "      <td>Facebook Ads</td>\n",
       "      <td>32</td>\n",
       "      <td>12.158</td>\n",
       "      <td>3.556</td>\n",
       "      <td>3.419</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>1654041600</td>\n",
       "      <td>43.151</td>\n",
       "      <td>54</td>\n",
       "      <td>#The Ultimate Fashion Statement with X</td>\n",
       "      <td>bridal jewelry</td>\n",
       "      <td>Google Ads</td>\n",
       "      <td>18</td>\n",
       "      <td>0.799</td>\n",
       "      <td>0.333</td>\n",
       "      <td>2.397</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>1654128000</td>\n",
       "      <td>31.436</td>\n",
       "      <td>55</td>\n",
       "      <td>#The Ultimate Fashion Statement with X</td>\n",
       "      <td>unique and trendy jewelry</td>\n",
       "      <td>DV360</td>\n",
       "      <td>12</td>\n",
       "      <td>0.572</td>\n",
       "      <td>0.218</td>\n",
       "      <td>2.620</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>1654387200</td>\n",
       "      <td>13.351</td>\n",
       "      <td>58</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>artisan jewelry</td>\n",
       "      <td>Facebook Ads</td>\n",
       "      <td>12</td>\n",
       "      <td>0.230</td>\n",
       "      <td>0.207</td>\n",
       "      <td>1.113</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>1654732800</td>\n",
       "      <td>13.629</td>\n",
       "      <td>62</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>rhinestone jewelry</td>\n",
       "      <td>Facebook Ads</td>\n",
       "      <td>10</td>\n",
       "      <td>0.220</td>\n",
       "      <td>0.161</td>\n",
       "      <td>1.363</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   index        time  media_cost_usd  no_of_days  \\\n",
       "0      0  1651536000         109.420           9   \n",
       "1      1  1654041600          43.151          54   \n",
       "2      2  1654128000          31.436          55   \n",
       "3      3  1654387200          13.351          58   \n",
       "4      4  1654732800          13.629          62   \n",
       "\n",
       "                              search_tags                   keywords  \\\n",
       "0      #Embrace Your Individuality with X            artisan jewelry   \n",
       "1  #The Ultimate Fashion Statement with X             bridal jewelry   \n",
       "2  #The Ultimate Fashion Statement with X  unique and trendy jewelry   \n",
       "3      #Embrace Your Individuality with X            artisan jewelry   \n",
       "4      #Embrace Your Individuality with X         rhinestone jewelry   \n",
       "\n",
       "  ext_service_name  clicks  daily_cost  daily_click  cost_per_click  \n",
       "0     Facebook Ads      32      12.158        3.556           3.419  \n",
       "1       Google Ads      18       0.799        0.333           2.397  \n",
       "2            DV360      12       0.572        0.218           2.620  \n",
       "3     Facebook Ads      12       0.230        0.207           1.113  \n",
       "4     Facebook Ads      10       0.220        0.161           1.363  "
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "filtered_dataset.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "13199ea2-2db0-48ae-b5bb-638bfbc82cdc",
   "metadata": {},
   "source": [
    "## Set up Superlinked"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "d2643bf2-87b9-4fe5-871f-e4efa418f665",
   "metadata": {},
   "outputs": [],
   "source": [
    "class Campaign(sl.Schema):\n",
    "    id: sl.IdField\n",
    "    start_date: sl.Timestamp\n",
    "    number_of_days: sl.Integer\n",
    "    creative: sl.String\n",
    "    keywords: sl.String\n",
    "    ext_service_name: sl.StringList\n",
    "    daily_cost: sl.Float\n",
    "    daily_click: sl.Float\n",
    "    cost_per_click: sl.Float"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "77215d1f-e209-457d-8a2b-0994df14c8a1",
   "metadata": {},
   "outputs": [],
   "source": [
    "campaign = Campaign()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "aad13a28-a754-45a6-93c8-b4c60e54f4b4",
   "metadata": {},
   "outputs": [],
   "source": [
    "# use parameters derived above from plots and tables\n",
    "recency_space = sl.RecencySpace(\n",
    "    timestamp=campaign.start_date,\n",
    "    period_time_list=[\n",
    "        sl.PeriodTime(timedelta(days=60)),\n",
    "        sl.PeriodTime(timedelta(days=180)),\n",
    "    ],\n",
    ")\n",
    "num_days_space = sl.NumberSpace(number=campaign.number_of_days, min_value=1, max_value=100, mode=sl.Mode.SIMILAR)\n",
    "daily_cost_space = sl.NumberSpace(number=campaign.daily_cost, min_value=0, max_value=50, mode=sl.Mode.SIMILAR)\n",
    "daily_click_space = sl.NumberSpace(number=campaign.daily_click, min_value=0, max_value=100, mode=sl.Mode.MAXIMUM)\n",
    "cost_per_click_space = sl.NumberSpace(number=campaign.daily_click, min_value=0, max_value=2, mode=sl.Mode.MINIMUM)\n",
    "service_space = sl.CategoricalSimilaritySpace(\n",
    "    category_input=campaign.ext_service_name,\n",
    "    categories=list(filtered_dataset[\"ext_service_name\"].unique()),\n",
    "    negative_filter=-5.0,\n",
    ")\n",
    "# textual data is simply encoded using a reasonably large and well performing model\n",
    "creative_space = sl.TextSimilaritySpace(text=campaign.creative, model=\"sentence-transformers/all-mpnet-base-v2\")\n",
    "keywords_space = sl.TextSimilaritySpace(text=campaign.keywords, model=\"sentence-transformers/all-mpnet-base-v2\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "7d3d5807-a044-4726-bb1a-d0f55d2f2bd9",
   "metadata": {},
   "outputs": [],
   "source": [
    "campaign_index = sl.Index(\n",
    "    spaces=[\n",
    "        recency_space,\n",
    "        num_days_space,\n",
    "        daily_cost_space,\n",
    "        daily_click_space,\n",
    "        cost_per_click_space,\n",
    "        service_space,\n",
    "        creative_space,\n",
    "        keywords_space,\n",
    "    ]\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "0fb6e19b-0f20-4b9d-961b-c6c0e27ffd86",
   "metadata": {},
   "outputs": [],
   "source": [
    "campaign_df_parser = sl.DataFrameParser(\n",
    "    schema=campaign,\n",
    "    mapping={\n",
    "        campaign.id: \"index\",\n",
    "        campaign.start_date: \"time\",\n",
    "        campaign.number_of_days: \"no_of_days\",\n",
    "        campaign.creative: \"search_tags\",\n",
    "    },\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "69cbb899-287b-41e1-98b7-756d56759729",
   "metadata": {},
   "outputs": [],
   "source": [
    "source_campaign: sl.InMemorySource = sl.InMemorySource(campaign, parser=campaign_df_parser)\n",
    "executor: sl.InMemoryExecutor = sl.InMemoryExecutor(\n",
    "    sources=[source_campaign], indices=[campaign_index], context_data=EXECUTOR_DATA\n",
    ")\n",
    "app: sl.InMemoryApp = executor.run()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "3e523a72-8eb3-4e00-9550-a21331c3f389",
   "metadata": {},
   "outputs": [],
   "source": [
    "source_campaign.put([filtered_dataset])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "31889165-6e55-4d79-9a6a-66fe9c254da8",
   "metadata": {},
   "source": [
    "## Run queries"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "7f0f8d1d-ee63-4efd-bba4-9816ad67dfb7",
   "metadata": {},
   "outputs": [],
   "source": [
    "# a query to browse campaign data without taking a specific campaign as base\n",
    "# define a versatile query and simply just switch in features as we go\n",
    "campaign_discovery_query = (\n",
    "    sl.Query(\n",
    "        campaign_index,\n",
    "        weights={\n",
    "            keywords_space: sl.Param(\"keywords_weight\"),\n",
    "            creative_space: sl.Param(\"creative_weight\"),\n",
    "            service_space: sl.Param(\"service_weight\"),\n",
    "            cost_per_click_space: sl.Param(\"cost_per_click_weight\"),\n",
    "            daily_cost_space: sl.Param(\"daily_cost_weight\"),\n",
    "            daily_click_space: sl.Param(\"daily_click_weight\"),\n",
    "            num_days_space: sl.Param(\"num_days_weight\"),\n",
    "            recency_space: sl.Param(\"recency_weight\"),\n",
    "        },\n",
    "    )\n",
    "    .find(campaign)\n",
    "    .similar(num_days_space, sl.Param(\"target_length_in_days\"))\n",
    "    .similar(daily_cost_space, sl.Param(\"target_daily_cost\"))\n",
    "    .similar(creative_space, sl.Param(\"target_creative\"))\n",
    "    .similar(keywords_space, sl.Param(\"target_keywords\"))\n",
    "    .similar(service_space, sl.Param(\"target_service\"))\n",
    "    .select_all()\n",
    "    .limit(sl.Param(\"limit\"))\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "f59af8b7-e791-44d8-aa7b-67f64b1ebcc8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>start_date</th>\n",
       "      <th>number_of_days</th>\n",
       "      <th>creative</th>\n",
       "      <th>keywords</th>\n",
       "      <th>ext_service_name</th>\n",
       "      <th>daily_cost</th>\n",
       "      <th>daily_click</th>\n",
       "      <th>cost_per_click</th>\n",
       "      <th>id</th>\n",
       "      <th>similarity_score</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2022-05-02</td>\n",
       "      <td>1</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>layered necklaces</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>489.513</td>\n",
       "      <td>1630.000</td>\n",
       "      <td>0.300</td>\n",
       "      <td>23169</td>\n",
       "      <td>0.074</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2022-05-02</td>\n",
       "      <td>1</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>body jewelry</td>\n",
       "      <td>[DV360]</td>\n",
       "      <td>396.772</td>\n",
       "      <td>1794.000</td>\n",
       "      <td>0.221</td>\n",
       "      <td>23194</td>\n",
       "      <td>0.074</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2022-05-03</td>\n",
       "      <td>2</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>seasonal jewelry</td>\n",
       "      <td>[DV360]</td>\n",
       "      <td>198.378</td>\n",
       "      <td>1029.000</td>\n",
       "      <td>0.193</td>\n",
       "      <td>23195</td>\n",
       "      <td>0.074</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2022-05-02</td>\n",
       "      <td>1</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>affordable trendy jewelry</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>346.197</td>\n",
       "      <td>1257.000</td>\n",
       "      <td>0.275</td>\n",
       "      <td>23253</td>\n",
       "      <td>0.074</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2022-05-11</td>\n",
       "      <td>4</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>affordable trendy jewelry</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>257.778</td>\n",
       "      <td>799.250</td>\n",
       "      <td>0.323</td>\n",
       "      <td>23382</td>\n",
       "      <td>0.074</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>2022-07-06</td>\n",
       "      <td>2</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>initial jewelry</td>\n",
       "      <td>[Google Ads]</td>\n",
       "      <td>166.715</td>\n",
       "      <td>326.000</td>\n",
       "      <td>0.511</td>\n",
       "      <td>7227</td>\n",
       "      <td>0.074</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>2022-08-21</td>\n",
       "      <td>2</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>festival jewelry</td>\n",
       "      <td>[Google Ads]</td>\n",
       "      <td>51.151</td>\n",
       "      <td>66.000</td>\n",
       "      <td>0.775</td>\n",
       "      <td>20826</td>\n",
       "      <td>0.074</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>2022-10-08</td>\n",
       "      <td>1</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>crystal jewelry</td>\n",
       "      <td>[Google Ads]</td>\n",
       "      <td>66.336</td>\n",
       "      <td>41.000</td>\n",
       "      <td>1.618</td>\n",
       "      <td>5019</td>\n",
       "      <td>0.074</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>2022-10-01</td>\n",
       "      <td>3</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>artisanal jewelry</td>\n",
       "      <td>[DV360]</td>\n",
       "      <td>73.403</td>\n",
       "      <td>1250.000</td>\n",
       "      <td>0.059</td>\n",
       "      <td>6770</td>\n",
       "      <td>0.074</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>2022-09-30</td>\n",
       "      <td>1</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>affordable statement jewelry</td>\n",
       "      <td>[Google Ads]</td>\n",
       "      <td>87.910</td>\n",
       "      <td>62.000</td>\n",
       "      <td>1.418</td>\n",
       "      <td>6778</td>\n",
       "      <td>0.074</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   start_date  number_of_days                            creative  \\\n",
       "0  2022-05-02               1  #Embrace Your Individuality with X   \n",
       "1  2022-05-02               1  #Embrace Your Individuality with X   \n",
       "2  2022-05-03               2  #Embrace Your Individuality with X   \n",
       "3  2022-05-02               1  #Embrace Your Individuality with X   \n",
       "4  2022-05-11               4  #Embrace Your Individuality with X   \n",
       "5  2022-07-06               2  #Embrace Your Individuality with X   \n",
       "6  2022-08-21               2  #Embrace Your Individuality with X   \n",
       "7  2022-10-08               1  #Embrace Your Individuality with X   \n",
       "8  2022-10-01               3  #Embrace Your Individuality with X   \n",
       "9  2022-09-30               1  #Embrace Your Individuality with X   \n",
       "\n",
       "                       keywords ext_service_name  daily_cost  daily_click  \\\n",
       "0             layered necklaces   [Facebook Ads]     489.513     1630.000   \n",
       "1                  body jewelry          [DV360]     396.772     1794.000   \n",
       "2              seasonal jewelry          [DV360]     198.378     1029.000   \n",
       "3     affordable trendy jewelry   [Facebook Ads]     346.197     1257.000   \n",
       "4     affordable trendy jewelry   [Facebook Ads]     257.778      799.250   \n",
       "5               initial jewelry     [Google Ads]     166.715      326.000   \n",
       "6              festival jewelry     [Google Ads]      51.151       66.000   \n",
       "7               crystal jewelry     [Google Ads]      66.336       41.000   \n",
       "8             artisanal jewelry          [DV360]      73.403     1250.000   \n",
       "9  affordable statement jewelry     [Google Ads]      87.910       62.000   \n",
       "\n",
       "   cost_per_click     id  similarity_score  \n",
       "0           0.300  23169             0.074  \n",
       "1           0.221  23194             0.074  \n",
       "2           0.193  23195             0.074  \n",
       "3           0.275  23253             0.074  \n",
       "4           0.323  23382             0.074  \n",
       "5           0.511   7227             0.074  \n",
       "6           0.775  20826             0.074  \n",
       "7           1.618   5019             0.074  \n",
       "8           0.059   6770             0.074  \n",
       "9           1.418   6778             0.074  "
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# first let's just switch the search on in terms of the text of the creative of the ad\n",
    "only_search_tag_results = app.query(\n",
    "    campaign_discovery_query,\n",
    "    keywords_weight=0,\n",
    "    creative_weight=1,\n",
    "    service_weight=0,\n",
    "    cost_per_click_weight=0,\n",
    "    daily_cost_weight=0,\n",
    "    daily_click_weight=0,\n",
    "    num_days_weight=0,\n",
    "    recency_weight=0,\n",
    "    target_length_in_days=0.0,\n",
    "    target_daily_cost=0,\n",
    "    target_creative=\"embrace your individuality\",\n",
    "    target_keywords=\"\",\n",
    "    target_service=\"\",\n",
    "    limit=10,\n",
    ")\n",
    "\n",
    "# these are essentially in random order, as there are only 2 distinct creatives at the moment\n",
    "df = sl.PandasConverter.to_pandas(only_search_tag_results)\n",
    "sl.PandasConverter.format_date_column(df, \"start_date\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "4a9ab6eb-f8db-4170-a078-962093b90ed8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>start_date</th>\n",
       "      <th>number_of_days</th>\n",
       "      <th>creative</th>\n",
       "      <th>keywords</th>\n",
       "      <th>ext_service_name</th>\n",
       "      <th>daily_cost</th>\n",
       "      <th>daily_click</th>\n",
       "      <th>cost_per_click</th>\n",
       "      <th>id</th>\n",
       "      <th>similarity_score</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2022-05-02</td>\n",
       "      <td>1</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>layered necklaces</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>489.513</td>\n",
       "      <td>1630.000</td>\n",
       "      <td>0.300</td>\n",
       "      <td>23169</td>\n",
       "      <td>0.132</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2022-05-02</td>\n",
       "      <td>1</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>affordable trendy jewelry</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>346.197</td>\n",
       "      <td>1257.000</td>\n",
       "      <td>0.275</td>\n",
       "      <td>23253</td>\n",
       "      <td>0.132</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2022-05-11</td>\n",
       "      <td>4</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>affordable trendy jewelry</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>257.778</td>\n",
       "      <td>799.250</td>\n",
       "      <td>0.323</td>\n",
       "      <td>23382</td>\n",
       "      <td>0.132</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2022-10-02</td>\n",
       "      <td>1</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>threader earrings</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>885.025</td>\n",
       "      <td>6569.000</td>\n",
       "      <td>0.135</td>\n",
       "      <td>23832</td>\n",
       "      <td>0.131</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2022-10-02</td>\n",
       "      <td>1</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>bold jewelry</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>1094.291</td>\n",
       "      <td>8090.000</td>\n",
       "      <td>0.135</td>\n",
       "      <td>23975</td>\n",
       "      <td>0.131</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>2022-10-01</td>\n",
       "      <td>3</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>formal jewelry</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>78.958</td>\n",
       "      <td>445.667</td>\n",
       "      <td>0.177</td>\n",
       "      <td>6006</td>\n",
       "      <td>0.131</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>2022-07-08</td>\n",
       "      <td>4</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>animal jewelry</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>55.599</td>\n",
       "      <td>178.500</td>\n",
       "      <td>0.311</td>\n",
       "      <td>6537</td>\n",
       "      <td>0.131</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>2022-07-06</td>\n",
       "      <td>2</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>zodiac jewelry</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>83.082</td>\n",
       "      <td>261.000</td>\n",
       "      <td>0.318</td>\n",
       "      <td>6586</td>\n",
       "      <td>0.131</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>2022-10-04</td>\n",
       "      <td>4</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>handmade jewelry</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>83.707</td>\n",
       "      <td>338.000</td>\n",
       "      <td>0.248</td>\n",
       "      <td>23561</td>\n",
       "      <td>0.131</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>2022-10-10</td>\n",
       "      <td>9</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>beach jewelry</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>136.750</td>\n",
       "      <td>507.444</td>\n",
       "      <td>0.269</td>\n",
       "      <td>23835</td>\n",
       "      <td>0.131</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   start_date  number_of_days                            creative  \\\n",
       "0  2022-05-02               1  #Embrace Your Individuality with X   \n",
       "1  2022-05-02               1  #Embrace Your Individuality with X   \n",
       "2  2022-05-11               4  #Embrace Your Individuality with X   \n",
       "3  2022-10-02               1  #Embrace Your Individuality with X   \n",
       "4  2022-10-02               1  #Embrace Your Individuality with X   \n",
       "5  2022-10-01               3  #Embrace Your Individuality with X   \n",
       "6  2022-07-08               4  #Embrace Your Individuality with X   \n",
       "7  2022-07-06               2  #Embrace Your Individuality with X   \n",
       "8  2022-10-04               4  #Embrace Your Individuality with X   \n",
       "9  2022-10-10               9  #Embrace Your Individuality with X   \n",
       "\n",
       "                    keywords ext_service_name  daily_cost  daily_click  \\\n",
       "0          layered necklaces   [Facebook Ads]     489.513     1630.000   \n",
       "1  affordable trendy jewelry   [Facebook Ads]     346.197     1257.000   \n",
       "2  affordable trendy jewelry   [Facebook Ads]     257.778      799.250   \n",
       "3          threader earrings   [Facebook Ads]     885.025     6569.000   \n",
       "4               bold jewelry   [Facebook Ads]    1094.291     8090.000   \n",
       "5             formal jewelry   [Facebook Ads]      78.958      445.667   \n",
       "6             animal jewelry   [Facebook Ads]      55.599      178.500   \n",
       "7             zodiac jewelry   [Facebook Ads]      83.082      261.000   \n",
       "8           handmade jewelry   [Facebook Ads]      83.707      338.000   \n",
       "9              beach jewelry   [Facebook Ads]     136.750      507.444   \n",
       "\n",
       "   cost_per_click     id  similarity_score  \n",
       "0           0.300  23169             0.132  \n",
       "1           0.275  23253             0.132  \n",
       "2           0.323  23382             0.132  \n",
       "3           0.135  23832             0.131  \n",
       "4           0.135  23975             0.131  \n",
       "5           0.177   6006             0.131  \n",
       "6           0.311   6537             0.131  \n",
       "7           0.318   6586             0.131  \n",
       "8           0.248  23561             0.131  \n",
       "9           0.269  23835             0.131  "
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# now let's only consider campaigns on Facebook\n",
    "search_tag_on_fb_result = app.query(\n",
    "    campaign_discovery_query,\n",
    "    keywords_weight=0,\n",
    "    creative_weight=1,\n",
    "    service_weight=1,\n",
    "    cost_per_click_weight=0,\n",
    "    daily_cost_weight=0,\n",
    "    daily_click_weight=0,\n",
    "    num_days_weight=0,\n",
    "    recency_weight=0,\n",
    "    target_length_in_days=0,\n",
    "    target_daily_cost=0,\n",
    "    target_creative=\"embrace your individuality\",\n",
    "    target_keywords=\"\",\n",
    "    target_service=\"Facebook Ads\",\n",
    "    limit=10,\n",
    ")\n",
    "\n",
    "df = sl.PandasConverter.to_pandas(search_tag_on_fb_result)\n",
    "sl.PandasConverter.format_date_column(df, \"start_date\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "059dfaf5-a860-4338-91fb-659527b5b621",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>start_date</th>\n",
       "      <th>number_of_days</th>\n",
       "      <th>creative</th>\n",
       "      <th>keywords</th>\n",
       "      <th>ext_service_name</th>\n",
       "      <th>daily_cost</th>\n",
       "      <th>daily_click</th>\n",
       "      <th>cost_per_click</th>\n",
       "      <th>id</th>\n",
       "      <th>similarity_score</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2022-06-11</td>\n",
       "      <td>29</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>party jewelry</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>2.859</td>\n",
       "      <td>11.862</td>\n",
       "      <td>0.241</td>\n",
       "      <td>23184</td>\n",
       "      <td>0.171</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2022-05-25</td>\n",
       "      <td>33</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>luxury jewelry</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>0.756</td>\n",
       "      <td>2.455</td>\n",
       "      <td>0.308</td>\n",
       "      <td>23173</td>\n",
       "      <td>0.171</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2022-06-08</td>\n",
       "      <td>26</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>minimalist jewelry</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>0.785</td>\n",
       "      <td>7.269</td>\n",
       "      <td>0.108</td>\n",
       "      <td>23272</td>\n",
       "      <td>0.171</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2022-09-17</td>\n",
       "      <td>30</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>dainty jewelry</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>2.515</td>\n",
       "      <td>9.333</td>\n",
       "      <td>0.269</td>\n",
       "      <td>5906</td>\n",
       "      <td>0.170</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2022-09-16</td>\n",
       "      <td>29</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>affordable statement jewelry</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>2.542</td>\n",
       "      <td>12.103</td>\n",
       "      <td>0.210</td>\n",
       "      <td>6663</td>\n",
       "      <td>0.170</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>2022-09-19</td>\n",
       "      <td>32</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>hoop earrings</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>2.430</td>\n",
       "      <td>6.406</td>\n",
       "      <td>0.379</td>\n",
       "      <td>7133</td>\n",
       "      <td>0.170</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>2022-09-29</td>\n",
       "      <td>28</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>dainty jewelry</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>0.645</td>\n",
       "      <td>3.071</td>\n",
       "      <td>0.210</td>\n",
       "      <td>5509</td>\n",
       "      <td>0.170</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>2022-08-20</td>\n",
       "      <td>28</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>affordable statement jewelry</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>2.036</td>\n",
       "      <td>9.964</td>\n",
       "      <td>0.204</td>\n",
       "      <td>5824</td>\n",
       "      <td>0.170</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>2022-09-15</td>\n",
       "      <td>28</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>spring jewelry</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>1.266</td>\n",
       "      <td>3.250</td>\n",
       "      <td>0.390</td>\n",
       "      <td>6411</td>\n",
       "      <td>0.170</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>2022-08-19</td>\n",
       "      <td>28</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>party jewelry</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>1.513</td>\n",
       "      <td>6.214</td>\n",
       "      <td>0.243</td>\n",
       "      <td>6444</td>\n",
       "      <td>0.170</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   start_date  number_of_days                            creative  \\\n",
       "0  2022-06-11              29  #Embrace Your Individuality with X   \n",
       "1  2022-05-25              33  #Embrace Your Individuality with X   \n",
       "2  2022-06-08              26  #Embrace Your Individuality with X   \n",
       "3  2022-09-17              30  #Embrace Your Individuality with X   \n",
       "4  2022-09-16              29  #Embrace Your Individuality with X   \n",
       "5  2022-09-19              32  #Embrace Your Individuality with X   \n",
       "6  2022-09-29              28  #Embrace Your Individuality with X   \n",
       "7  2022-08-20              28  #Embrace Your Individuality with X   \n",
       "8  2022-09-15              28  #Embrace Your Individuality with X   \n",
       "9  2022-08-19              28  #Embrace Your Individuality with X   \n",
       "\n",
       "                       keywords ext_service_name  daily_cost  daily_click  \\\n",
       "0                 party jewelry   [Facebook Ads]       2.859       11.862   \n",
       "1                luxury jewelry   [Facebook Ads]       0.756        2.455   \n",
       "2            minimalist jewelry   [Facebook Ads]       0.785        7.269   \n",
       "3                dainty jewelry   [Facebook Ads]       2.515        9.333   \n",
       "4  affordable statement jewelry   [Facebook Ads]       2.542       12.103   \n",
       "5                 hoop earrings   [Facebook Ads]       2.430        6.406   \n",
       "6                dainty jewelry   [Facebook Ads]       0.645        3.071   \n",
       "7  affordable statement jewelry   [Facebook Ads]       2.036        9.964   \n",
       "8                spring jewelry   [Facebook Ads]       1.266        3.250   \n",
       "9                 party jewelry   [Facebook Ads]       1.513        6.214   \n",
       "\n",
       "   cost_per_click     id  similarity_score  \n",
       "0           0.241  23184             0.171  \n",
       "1           0.308  23173             0.171  \n",
       "2           0.108  23272             0.171  \n",
       "3           0.269   5906             0.170  \n",
       "4           0.210   6663             0.170  \n",
       "5           0.379   7133             0.170  \n",
       "6           0.210   5509             0.170  \n",
       "7           0.204   5824             0.170  \n",
       "8           0.390   6411             0.170  \n",
       "9           0.243   6444             0.170  "
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# now let's take into account that we are looking for ~30 day campaigns\n",
    "search_tag_fb_30_days_results = app.query(\n",
    "    campaign_discovery_query,\n",
    "    keywords_weight=0,\n",
    "    creative_weight=1,\n",
    "    service_weight=1,\n",
    "    cost_per_click_weight=0,\n",
    "    daily_cost_weight=0,\n",
    "    daily_click_weight=0,\n",
    "    num_days_weight=1,\n",
    "    recency_weight=0,\n",
    "    target_length_in_days=30.0,\n",
    "    target_daily_cost=0,\n",
    "    target_creative=\"embrace your individuality\",\n",
    "    target_keywords=\"\",\n",
    "    target_service=\"Facebook Ads\",\n",
    "    limit=10,\n",
    ")\n",
    "\n",
    "df = sl.PandasConverter.to_pandas(search_tag_fb_30_days_results)\n",
    "sl.PandasConverter.format_date_column(df, \"start_date\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "9c44e15e-08da-4dd5-ac93-30e6f800694a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>start_date</th>\n",
       "      <th>number_of_days</th>\n",
       "      <th>creative</th>\n",
       "      <th>keywords</th>\n",
       "      <th>ext_service_name</th>\n",
       "      <th>daily_cost</th>\n",
       "      <th>daily_click</th>\n",
       "      <th>cost_per_click</th>\n",
       "      <th>id</th>\n",
       "      <th>similarity_score</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2022-05-25</td>\n",
       "      <td>33</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>luxury jewelry</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>0.756</td>\n",
       "      <td>2.455</td>\n",
       "      <td>0.308</td>\n",
       "      <td>23173</td>\n",
       "      <td>0.204</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2022-06-08</td>\n",
       "      <td>26</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>minimalist jewelry</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>0.785</td>\n",
       "      <td>7.269</td>\n",
       "      <td>0.108</td>\n",
       "      <td>23272</td>\n",
       "      <td>0.204</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2022-06-11</td>\n",
       "      <td>29</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>party jewelry</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>2.859</td>\n",
       "      <td>11.862</td>\n",
       "      <td>0.241</td>\n",
       "      <td>23184</td>\n",
       "      <td>0.203</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2022-09-29</td>\n",
       "      <td>28</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>dainty jewelry</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>0.645</td>\n",
       "      <td>3.071</td>\n",
       "      <td>0.210</td>\n",
       "      <td>5509</td>\n",
       "      <td>0.203</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2022-08-20</td>\n",
       "      <td>28</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>rhinestone jewelry</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>0.816</td>\n",
       "      <td>2.607</td>\n",
       "      <td>0.313</td>\n",
       "      <td>7415</td>\n",
       "      <td>0.203</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>2022-08-23</td>\n",
       "      <td>28</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>charm bracelets</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>1.178</td>\n",
       "      <td>5.321</td>\n",
       "      <td>0.221</td>\n",
       "      <td>24190</td>\n",
       "      <td>0.203</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>2022-09-15</td>\n",
       "      <td>28</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>spring jewelry</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>1.266</td>\n",
       "      <td>3.250</td>\n",
       "      <td>0.390</td>\n",
       "      <td>6411</td>\n",
       "      <td>0.203</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>2022-08-19</td>\n",
       "      <td>28</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>party jewelry</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>1.513</td>\n",
       "      <td>6.214</td>\n",
       "      <td>0.243</td>\n",
       "      <td>6444</td>\n",
       "      <td>0.203</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>2022-09-07</td>\n",
       "      <td>33</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>casual jewelry</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>0.679</td>\n",
       "      <td>2.121</td>\n",
       "      <td>0.320</td>\n",
       "      <td>23919</td>\n",
       "      <td>0.203</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>2022-09-15</td>\n",
       "      <td>28</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>layered bracelets</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>1.701</td>\n",
       "      <td>7.214</td>\n",
       "      <td>0.236</td>\n",
       "      <td>9478</td>\n",
       "      <td>0.203</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   start_date  number_of_days                            creative  \\\n",
       "0  2022-05-25              33  #Embrace Your Individuality with X   \n",
       "1  2022-06-08              26  #Embrace Your Individuality with X   \n",
       "2  2022-06-11              29  #Embrace Your Individuality with X   \n",
       "3  2022-09-29              28  #Embrace Your Individuality with X   \n",
       "4  2022-08-20              28  #Embrace Your Individuality with X   \n",
       "5  2022-08-23              28  #Embrace Your Individuality with X   \n",
       "6  2022-09-15              28  #Embrace Your Individuality with X   \n",
       "7  2022-08-19              28  #Embrace Your Individuality with X   \n",
       "8  2022-09-07              33  #Embrace Your Individuality with X   \n",
       "9  2022-09-15              28  #Embrace Your Individuality with X   \n",
       "\n",
       "             keywords ext_service_name  daily_cost  daily_click  \\\n",
       "0      luxury jewelry   [Facebook Ads]       0.756        2.455   \n",
       "1  minimalist jewelry   [Facebook Ads]       0.785        7.269   \n",
       "2       party jewelry   [Facebook Ads]       2.859       11.862   \n",
       "3      dainty jewelry   [Facebook Ads]       0.645        3.071   \n",
       "4  rhinestone jewelry   [Facebook Ads]       0.816        2.607   \n",
       "5     charm bracelets   [Facebook Ads]       1.178        5.321   \n",
       "6      spring jewelry   [Facebook Ads]       1.266        3.250   \n",
       "7       party jewelry   [Facebook Ads]       1.513        6.214   \n",
       "8      casual jewelry   [Facebook Ads]       0.679        2.121   \n",
       "9   layered bracelets   [Facebook Ads]       1.701        7.214   \n",
       "\n",
       "   cost_per_click     id  similarity_score  \n",
       "0           0.308  23173             0.204  \n",
       "1           0.108  23272             0.204  \n",
       "2           0.241  23184             0.203  \n",
       "3           0.210   5509             0.203  \n",
       "4           0.313   7415             0.203  \n",
       "5           0.221  24190             0.203  \n",
       "6           0.390   6411             0.203  \n",
       "7           0.243   6444             0.203  \n",
       "8           0.320  23919             0.203  \n",
       "9           0.236   9478             0.203  "
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# let's also factor in that we aim to spend 0.5 thousand USDs a day\n",
    "search_tag_fb_30_days_daily_05_results = app.query(\n",
    "    campaign_discovery_query,\n",
    "    keywords_weight=0,\n",
    "    creative_weight=1,\n",
    "    service_weight=1,\n",
    "    cost_per_click_weight=0,\n",
    "    daily_cost_weight=1,\n",
    "    daily_click_weight=0,\n",
    "    num_days_weight=1,\n",
    "    recency_weight=0,\n",
    "    target_length_in_days=30.0,\n",
    "    target_daily_cost=0.5,\n",
    "    target_creative=\"embrace your individuality\",\n",
    "    target_keywords=\"\",\n",
    "    target_service=\"Facebook Ads\",\n",
    "    limit=10,\n",
    ")\n",
    "\n",
    "# some extremely low spending campaigns now disappeared from the top results\n",
    "df = sl.PandasConverter().to_pandas(search_tag_fb_30_days_daily_05_results)\n",
    "sl.PandasConverter.format_date_column(df, \"start_date\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d23039d4-275b-4a9e-a4cd-e36ffc768e6e",
   "metadata": {},
   "source": [
    "### Optimize for a target\n",
    "\n",
    "Now let's also blend in that we are looking for the best campaigns within these soft filters"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "946aa5fe-a516-4ee0-95a3-a86f0c785047",
   "metadata": {},
   "source": [
    "#### Clicks"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "8cc8e513-c2d1-4fda-88ab-55193b9aa354",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>start_date</th>\n",
       "      <th>number_of_days</th>\n",
       "      <th>creative</th>\n",
       "      <th>keywords</th>\n",
       "      <th>ext_service_name</th>\n",
       "      <th>daily_cost</th>\n",
       "      <th>daily_click</th>\n",
       "      <th>cost_per_click</th>\n",
       "      <th>id</th>\n",
       "      <th>similarity_score</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2022-09-01</td>\n",
       "      <td>24</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>formal jewelry</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>1.428</td>\n",
       "      <td>150.833</td>\n",
       "      <td>0.009</td>\n",
       "      <td>5427</td>\n",
       "      <td>0.208</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2022-08-30</td>\n",
       "      <td>25</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>animal jewelry</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>3.945</td>\n",
       "      <td>342.040</td>\n",
       "      <td>0.012</td>\n",
       "      <td>23932</td>\n",
       "      <td>0.208</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2022-08-31</td>\n",
       "      <td>26</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>bridal jewelry</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>4.718</td>\n",
       "      <td>354.462</td>\n",
       "      <td>0.013</td>\n",
       "      <td>23784</td>\n",
       "      <td>0.207</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2022-09-04</td>\n",
       "      <td>17</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>designer-inspired jewelry</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>2.315</td>\n",
       "      <td>97.824</td>\n",
       "      <td>0.024</td>\n",
       "      <td>24268</td>\n",
       "      <td>0.207</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2022-09-02</td>\n",
       "      <td>15</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>everyday jewelry</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>4.927</td>\n",
       "      <td>425.333</td>\n",
       "      <td>0.012</td>\n",
       "      <td>23951</td>\n",
       "      <td>0.206</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>2022-08-31</td>\n",
       "      <td>13</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>casual jewelry</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>3.030</td>\n",
       "      <td>117.615</td>\n",
       "      <td>0.026</td>\n",
       "      <td>24266</td>\n",
       "      <td>0.206</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>2022-08-29</td>\n",
       "      <td>24</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>luxury jewelry</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>5.053</td>\n",
       "      <td>51.958</td>\n",
       "      <td>0.097</td>\n",
       "      <td>6905</td>\n",
       "      <td>0.206</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>2022-09-03</td>\n",
       "      <td>16</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>concert jewelry</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>3.480</td>\n",
       "      <td>58.562</td>\n",
       "      <td>0.059</td>\n",
       "      <td>23463</td>\n",
       "      <td>0.205</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>2022-08-31</td>\n",
       "      <td>13</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>everyday jewelry</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>5.750</td>\n",
       "      <td>85.385</td>\n",
       "      <td>0.067</td>\n",
       "      <td>23711</td>\n",
       "      <td>0.205</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>2022-10-16</td>\n",
       "      <td>18</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>victorian jewelry</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>6.628</td>\n",
       "      <td>66.056</td>\n",
       "      <td>0.100</td>\n",
       "      <td>6776</td>\n",
       "      <td>0.205</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   start_date  number_of_days                            creative  \\\n",
       "0  2022-09-01              24  #Embrace Your Individuality with X   \n",
       "1  2022-08-30              25  #Embrace Your Individuality with X   \n",
       "2  2022-08-31              26  #Embrace Your Individuality with X   \n",
       "3  2022-09-04              17  #Embrace Your Individuality with X   \n",
       "4  2022-09-02              15  #Embrace Your Individuality with X   \n",
       "5  2022-08-31              13  #Embrace Your Individuality with X   \n",
       "6  2022-08-29              24  #Embrace Your Individuality with X   \n",
       "7  2022-09-03              16  #Embrace Your Individuality with X   \n",
       "8  2022-08-31              13  #Embrace Your Individuality with X   \n",
       "9  2022-10-16              18  #Embrace Your Individuality with X   \n",
       "\n",
       "                    keywords ext_service_name  daily_cost  daily_click  \\\n",
       "0             formal jewelry   [Facebook Ads]       1.428      150.833   \n",
       "1             animal jewelry   [Facebook Ads]       3.945      342.040   \n",
       "2             bridal jewelry   [Facebook Ads]       4.718      354.462   \n",
       "3  designer-inspired jewelry   [Facebook Ads]       2.315       97.824   \n",
       "4           everyday jewelry   [Facebook Ads]       4.927      425.333   \n",
       "5             casual jewelry   [Facebook Ads]       3.030      117.615   \n",
       "6             luxury jewelry   [Facebook Ads]       5.053       51.958   \n",
       "7            concert jewelry   [Facebook Ads]       3.480       58.562   \n",
       "8           everyday jewelry   [Facebook Ads]       5.750       85.385   \n",
       "9          victorian jewelry   [Facebook Ads]       6.628       66.056   \n",
       "\n",
       "   cost_per_click     id  similarity_score  \n",
       "0           0.009   5427             0.208  \n",
       "1           0.012  23932             0.208  \n",
       "2           0.013  23784             0.207  \n",
       "3           0.024  24268             0.207  \n",
       "4           0.012  23951             0.206  \n",
       "5           0.026  24266             0.206  \n",
       "6           0.097   6905             0.206  \n",
       "7           0.059  23463             0.205  \n",
       "8           0.067  23711             0.205  \n",
       "9           0.100   6776             0.205  "
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# get the most clicks without regard to cost\n",
    "search_click_optim_results = app.query(\n",
    "    campaign_discovery_query,\n",
    "    keywords_weight=0,\n",
    "    creative_weight=1,\n",
    "    service_weight=1,\n",
    "    cost_per_click_weight=0,\n",
    "    daily_cost_weight=1,\n",
    "    daily_click_weight=0.1,\n",
    "    num_days_weight=1,\n",
    "    recency_weight=0,\n",
    "    target_length_in_days=30.0,\n",
    "    target_daily_cost=0.5,\n",
    "    target_creative=\"embrace your individuality\",\n",
    "    target_keywords=\"\",\n",
    "    target_service=\"Facebook Ads\",\n",
    "    limit=10,\n",
    ")\n",
    "\n",
    "# high click creating campaigns are at the top - regardless of their cost\n",
    "df = sl.PandasConverter().to_pandas(search_click_optim_results)\n",
    "sl.PandasConverter.format_date_column(df, \"start_date\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "7e0e8736-54ad-4186-a26b-930186309ea4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>start_date</th>\n",
       "      <th>number_of_days</th>\n",
       "      <th>creative</th>\n",
       "      <th>keywords</th>\n",
       "      <th>ext_service_name</th>\n",
       "      <th>daily_cost</th>\n",
       "      <th>daily_click</th>\n",
       "      <th>cost_per_click</th>\n",
       "      <th>id</th>\n",
       "      <th>similarity_score</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2022-09-01</td>\n",
       "      <td>24</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>formal jewelry</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>1.428</td>\n",
       "      <td>150.833</td>\n",
       "      <td>0.009</td>\n",
       "      <td>5427</td>\n",
       "      <td>0.211</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2022-08-30</td>\n",
       "      <td>25</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>animal jewelry</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>3.945</td>\n",
       "      <td>342.040</td>\n",
       "      <td>0.012</td>\n",
       "      <td>23932</td>\n",
       "      <td>0.211</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2022-08-31</td>\n",
       "      <td>26</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>bridal jewelry</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>4.718</td>\n",
       "      <td>354.462</td>\n",
       "      <td>0.013</td>\n",
       "      <td>23784</td>\n",
       "      <td>0.210</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2022-09-04</td>\n",
       "      <td>17</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>designer-inspired jewelry</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>2.315</td>\n",
       "      <td>97.824</td>\n",
       "      <td>0.024</td>\n",
       "      <td>24268</td>\n",
       "      <td>0.210</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2022-09-02</td>\n",
       "      <td>15</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>everyday jewelry</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>4.927</td>\n",
       "      <td>425.333</td>\n",
       "      <td>0.012</td>\n",
       "      <td>23951</td>\n",
       "      <td>0.209</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>2022-08-31</td>\n",
       "      <td>13</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>casual jewelry</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>3.030</td>\n",
       "      <td>117.615</td>\n",
       "      <td>0.026</td>\n",
       "      <td>24266</td>\n",
       "      <td>0.209</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>2022-08-29</td>\n",
       "      <td>11</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>modern jewelry</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>6.700</td>\n",
       "      <td>170.818</td>\n",
       "      <td>0.039</td>\n",
       "      <td>23949</td>\n",
       "      <td>0.208</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>2022-08-29</td>\n",
       "      <td>11</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>stud earrings</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>6.767</td>\n",
       "      <td>128.636</td>\n",
       "      <td>0.053</td>\n",
       "      <td>24072</td>\n",
       "      <td>0.208</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>2022-08-31</td>\n",
       "      <td>13</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>everyday jewelry</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>5.750</td>\n",
       "      <td>85.385</td>\n",
       "      <td>0.067</td>\n",
       "      <td>23711</td>\n",
       "      <td>0.208</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>2022-10-09</td>\n",
       "      <td>11</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>cuff bracelets</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>13.028</td>\n",
       "      <td>87.000</td>\n",
       "      <td>0.150</td>\n",
       "      <td>6810</td>\n",
       "      <td>0.205</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   start_date  number_of_days                            creative  \\\n",
       "0  2022-09-01              24  #Embrace Your Individuality with X   \n",
       "1  2022-08-30              25  #Embrace Your Individuality with X   \n",
       "2  2022-08-31              26  #Embrace Your Individuality with X   \n",
       "3  2022-09-04              17  #Embrace Your Individuality with X   \n",
       "4  2022-09-02              15  #Embrace Your Individuality with X   \n",
       "5  2022-08-31              13  #Embrace Your Individuality with X   \n",
       "6  2022-08-29              11  #Embrace Your Individuality with X   \n",
       "7  2022-08-29              11  #Embrace Your Individuality with X   \n",
       "8  2022-08-31              13  #Embrace Your Individuality with X   \n",
       "9  2022-10-09              11  #Embrace Your Individuality with X   \n",
       "\n",
       "                    keywords ext_service_name  daily_cost  daily_click  \\\n",
       "0             formal jewelry   [Facebook Ads]       1.428      150.833   \n",
       "1             animal jewelry   [Facebook Ads]       3.945      342.040   \n",
       "2             bridal jewelry   [Facebook Ads]       4.718      354.462   \n",
       "3  designer-inspired jewelry   [Facebook Ads]       2.315       97.824   \n",
       "4           everyday jewelry   [Facebook Ads]       4.927      425.333   \n",
       "5             casual jewelry   [Facebook Ads]       3.030      117.615   \n",
       "6             modern jewelry   [Facebook Ads]       6.700      170.818   \n",
       "7              stud earrings   [Facebook Ads]       6.767      128.636   \n",
       "8           everyday jewelry   [Facebook Ads]       5.750       85.385   \n",
       "9             cuff bracelets   [Facebook Ads]      13.028       87.000   \n",
       "\n",
       "   cost_per_click     id  similarity_score  \n",
       "0           0.009   5427             0.211  \n",
       "1           0.012  23932             0.211  \n",
       "2           0.013  23784             0.210  \n",
       "3           0.024  24268             0.210  \n",
       "4           0.012  23951             0.209  \n",
       "5           0.026  24266             0.209  \n",
       "6           0.039  23949             0.208  \n",
       "7           0.053  24072             0.208  \n",
       "8           0.067  23711             0.208  \n",
       "9           0.150   6810             0.205  "
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# take it to the extreme - be more lenient with daily_cost and no_of_days thresholds\n",
    "# and favor better performing campaigns\n",
    "extreme_search_click_optim_results = app.query(\n",
    "    campaign_discovery_query,\n",
    "    keywords_weight=0,\n",
    "    creative_weight=1,\n",
    "    service_weight=1,\n",
    "    cost_per_click_weight=0,\n",
    "    daily_cost_weight=1,\n",
    "    daily_click_weight=1,\n",
    "    num_days_weight=1,\n",
    "    recency_weight=0,\n",
    "    target_length_in_days=30.0,\n",
    "    target_daily_cost=0.5,\n",
    "    target_creative=\"embrace your individuality\",\n",
    "    target_keywords=\"\",\n",
    "    target_service=\"Facebook Ads\",\n",
    "    limit=10,\n",
    ")\n",
    "\n",
    "# the results focus even more on the clicks the campaign was able to generate\n",
    "df = sl.PandasConverter().to_pandas(extreme_search_click_optim_results)\n",
    "sl.PandasConverter.format_date_column(df, \"start_date\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5675a383-8b37-44a5-be58-95dcd1c03ede",
   "metadata": {},
   "source": [
    "#### Cost"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "01338538-2daa-4f96-95ef-14f708622af5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>start_date</th>\n",
       "      <th>number_of_days</th>\n",
       "      <th>creative</th>\n",
       "      <th>keywords</th>\n",
       "      <th>ext_service_name</th>\n",
       "      <th>daily_cost</th>\n",
       "      <th>daily_click</th>\n",
       "      <th>cost_per_click</th>\n",
       "      <th>id</th>\n",
       "      <th>similarity_score</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2022-08-21</td>\n",
       "      <td>31</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>bridal jewelry</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>0.037</td>\n",
       "      <td>0.065</td>\n",
       "      <td>0.574</td>\n",
       "      <td>15723</td>\n",
       "      <td>0.210</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2022-07-22</td>\n",
       "      <td>32</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>hoop earrings</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>0.005</td>\n",
       "      <td>0.062</td>\n",
       "      <td>0.074</td>\n",
       "      <td>20962</td>\n",
       "      <td>0.210</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2022-07-14</td>\n",
       "      <td>28</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>statement rings</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>0.006</td>\n",
       "      <td>0.071</td>\n",
       "      <td>0.088</td>\n",
       "      <td>17259</td>\n",
       "      <td>0.210</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2022-07-19</td>\n",
       "      <td>33</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>renaissance jewelry</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>0.026</td>\n",
       "      <td>0.091</td>\n",
       "      <td>0.281</td>\n",
       "      <td>11496</td>\n",
       "      <td>0.210</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2022-08-05</td>\n",
       "      <td>32</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>colorful jewelry</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>0.046</td>\n",
       "      <td>0.125</td>\n",
       "      <td>0.367</td>\n",
       "      <td>22981</td>\n",
       "      <td>0.209</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>2022-09-19</td>\n",
       "      <td>32</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>affordable statement jewelry</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>0.009</td>\n",
       "      <td>0.125</td>\n",
       "      <td>0.070</td>\n",
       "      <td>7128</td>\n",
       "      <td>0.209</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>2022-09-01</td>\n",
       "      <td>30</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>chunky jewelry</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>0.124</td>\n",
       "      <td>0.133</td>\n",
       "      <td>0.927</td>\n",
       "      <td>16796</td>\n",
       "      <td>0.209</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>2022-08-20</td>\n",
       "      <td>30</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>baroque jewelry</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>0.038</td>\n",
       "      <td>0.133</td>\n",
       "      <td>0.283</td>\n",
       "      <td>15722</td>\n",
       "      <td>0.209</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>2022-08-31</td>\n",
       "      <td>30</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>zodiac jewelry</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>0.022</td>\n",
       "      <td>0.133</td>\n",
       "      <td>0.163</td>\n",
       "      <td>2591</td>\n",
       "      <td>0.209</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>2022-08-26</td>\n",
       "      <td>24</td>\n",
       "      <td>#Embrace Your Individuality with X</td>\n",
       "      <td>drop earrings</td>\n",
       "      <td>[Facebook Ads]</td>\n",
       "      <td>0.020</td>\n",
       "      <td>0.083</td>\n",
       "      <td>0.239</td>\n",
       "      <td>16738</td>\n",
       "      <td>0.209</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   start_date  number_of_days                            creative  \\\n",
       "0  2022-08-21              31  #Embrace Your Individuality with X   \n",
       "1  2022-07-22              32  #Embrace Your Individuality with X   \n",
       "2  2022-07-14              28  #Embrace Your Individuality with X   \n",
       "3  2022-07-19              33  #Embrace Your Individuality with X   \n",
       "4  2022-08-05              32  #Embrace Your Individuality with X   \n",
       "5  2022-09-19              32  #Embrace Your Individuality with X   \n",
       "6  2022-09-01              30  #Embrace Your Individuality with X   \n",
       "7  2022-08-20              30  #Embrace Your Individuality with X   \n",
       "8  2022-08-31              30  #Embrace Your Individuality with X   \n",
       "9  2022-08-26              24  #Embrace Your Individuality with X   \n",
       "\n",
       "                       keywords ext_service_name  daily_cost  daily_click  \\\n",
       "0                bridal jewelry   [Facebook Ads]       0.037        0.065   \n",
       "1                 hoop earrings   [Facebook Ads]       0.005        0.062   \n",
       "2               statement rings   [Facebook Ads]       0.006        0.071   \n",
       "3           renaissance jewelry   [Facebook Ads]       0.026        0.091   \n",
       "4              colorful jewelry   [Facebook Ads]       0.046        0.125   \n",
       "5  affordable statement jewelry   [Facebook Ads]       0.009        0.125   \n",
       "6                chunky jewelry   [Facebook Ads]       0.124        0.133   \n",
       "7               baroque jewelry   [Facebook Ads]       0.038        0.133   \n",
       "8                zodiac jewelry   [Facebook Ads]       0.022        0.133   \n",
       "9                 drop earrings   [Facebook Ads]       0.020        0.083   \n",
       "\n",
       "   cost_per_click     id  similarity_score  \n",
       "0           0.574  15723             0.210  \n",
       "1           0.074  20962             0.210  \n",
       "2           0.088  17259             0.210  \n",
       "3           0.281  11496             0.210  \n",
       "4           0.367  22981             0.209  \n",
       "5           0.070   7128             0.209  \n",
       "6           0.927  16796             0.209  \n",
       "7           0.283  15722             0.209  \n",
       "8           0.163   2591             0.209  \n",
       "9           0.239  16738             0.209  "
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Find the most efficient campaigns in terms of cost_per_click\n",
    "search_cost_optim_results = app.query(\n",
    "    campaign_discovery_query,\n",
    "    keywords_weight=0,\n",
    "    creative_weight=1,\n",
    "    service_weight=1,\n",
    "    cost_per_click_weight=1,\n",
    "    daily_cost_weight=1,\n",
    "    daily_click_weight=0,\n",
    "    num_days_weight=1,\n",
    "    recency_weight=0,\n",
    "    target_length_in_days=30.0,\n",
    "    target_daily_cost=0.5,\n",
    "    target_creative=\"embrace your individuality\",\n",
    "    target_keywords=\"\",\n",
    "    target_service=\"Facebook Ads\",\n",
    "    limit=10,\n",
    ")\n",
    "\n",
    "df = sl.PandasConverter().to_pandas(search_cost_optim_results)\n",
    "sl.PandasConverter.format_date_column(df, \"start_date\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "34634a96-9eb1-4072-9373-41a069bf5aaa",
   "metadata": {},
   "source": [
    "## What we achieved\n",
    "\n",
    "Using Superlinked we were able to drill through our campaign dataset by gradually building up a collection of result sets where we are\n",
    "\n",
    "1. softly favoring campaigns that are similar to our planned one in terms of:\n",
    "    * length,\n",
    "    * budget,\n",
    "    * the ad platform we are targeting and\n",
    "    * creative text.\n",
    "<br/><br/>\n",
    "2. optimize for different metrics having fine-grained control over the tradeoff of relaxing our constraints, but getting better performing campaigns."
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
